package com.servlet;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;

import com.e.BaseServlet;
import com.entity.UserBean;

/**
 * Servlet implementation class TestELServlet
 */
public class TestELServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
   
	public void test1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setAttribute("str", "hello");
		request.setAttribute("str2", "word");
		request.setAttribute("str3", 1);
		request.setAttribute("str4", 5);
		Object obj=new Object();
		request.setAttribute("str5", obj);
		request.setAttribute("str6", obj);
		
		HttpSession session=request.getSession();//会话
		session.setAttribute("userName", "zjl");
		ServletContext sContext=session.getServletContext();//应用
		sContext.setAttribute("userName", "应用");
		
		request.getRequestDispatcher("el1.jsp").forward(request, response);
	}
	public void test2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String nameString = request.getParameter("name");
		request.setAttribute("str", nameString);
		request.setAttribute("str2", "hello");
		request.setAttribute("str3", 55);
		request.setAttribute("str4", 11);
		Object obj=new Object();
		request.setAttribute("str5", obj);
		request.setAttribute("str6", obj);
		request.getRequestDispatcher("el1.jsp").forward(request, response);
	}
	
	public void userDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		UserBean userBean=new UserBean("zjl","20","男","101");
		request.setAttribute("user", userBean);
		request.getRequestDispatcher("userDetail.jsp").forward(request, response);
	}
	public void test3(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setAttribute("val", "request作用域");
		request.setAttribute("name1", "request作用域name1");
		HttpSession session=request.getSession();//会话
		session.setAttribute("val", "session作用域");
		session.setAttribute("name2", "session作用域name2");
		ServletContext sContext=session.getServletContext();//应用
		sContext.setAttribute("val", "sContext作用域");
		sContext.setAttribute("name3", "sContext作用域name3");
		request.getRequestDispatcher("el3.jsp").forward(request, response);
	}

}
